package verify

import (
	"github.com/hwcer/cosgo"
	"github.com/hwcer/updater"
	"github.com/hwcer/yyds/players/verify"
	"server/game/cache"
	"server/game/model"
	"server/share/config"
)

func init() {
	cosgo.On(cosgo.EventTypLoaded, func() error {
		verify.SetMethod(config.Data.Functions.ChipLevelCountNum, ChipLevelCountNum)
		return nil
	})
}

func ChipLevelCountNum(u *updater.Updater, value verify.Value) (r int64) {
	items := cache.GetItems(u)
	args := value.GetArgs()
	if len(args) == 0 {
		return 0
	}

	items.RangeWithIType(config.ITypeChip, func(s string, v *model.Items) bool {
		lv := v.Attach.GetInt32(model.AttachChipLv)
		if lv >= args[0] {
			r += 1
		}
		return true
	})

	return
}
